package tbdp.tool.core.loader;

import java.util.ServiceLoader;

import tbdp.tool.container.ProcessorContainer;
import tbdp.tool.container.ReaderContainer;
import tbdp.tool.container.WriterContainer;
import tbdp.tool.spi.Processor;
import tbdp.tool.spi.Reader;
import tbdp.tool.spi.Writer;

/**
 * @author xbkaishui
 * @version $Id: ServiceLoaderUtil.java, v 0.1 2017-06-17 下午4:20 xbkaishui Exp $$
 */
public class ServiceLoaderUtil {

    public static void loadProcess() {
        ServiceLoader<Processor> processors = ServiceLoader.load(Processor.class);
        for (Processor processor : processors) {
            ProcessorContainer.addProcessor(processor);
        }
    }

    public static void loadReader() {
        ServiceLoader<Reader> readers = ServiceLoader.load(Reader.class);
        for (Reader reader : readers) {
            ReaderContainer.addReader(reader);
        }
    }

    public static void loadWriter() {
        ServiceLoader<Writer> writers = ServiceLoader.load(Writer.class);
        for (Writer writer : writers) {
            WriterContainer.addWriter(writer);
        }
    }
}
